package com.cetcs.kmga.dataManager.controller;

import com.alibaba.fastjson.JSON;
import com.cetc.cloud.kmga.util.DateUtils;
import com.cetcs.kmga.common.*;
import com.cetcs.kmga.dataManager.annotation.LogAnnotation;
import com.cetcs.kmga.dataManager.dao.hbase.LogPage;
import com.cetcs.kmga.dataManager.entity.global.LogLevelEnum;
import com.cetcs.kmga.dataManager.entity.global.LogTypeEnum;
import com.cetcs.kmga.dataManager.entity.logManager.vi.*;
import com.cetcs.kmga.dataManager.global.ResLogType;
import com.cetcs.kmga.dataManager.service.log.LogManagerService;
import com.cetcs.kmga.dataManager.util.BeanToMapUtil;
import com.cetcs.kmga.dataManager.util.ExcelExportUtil;
import com.cetcs.kmga.dataManager.util.JsonUtil;
import com.cetcs.kmga.dataManager.util.KmgaDefinedException;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.lang.reflect.FieldUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.WebRequest;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.beans.IntrospectionException;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 日志管理
 *
 * @author yyangs
 * @version V1.0 创建时间：2017-08-30 13:40
 * Copyright 2017 by CETC
 */
@RestController
@RequestMapping("/logManager")
public class LogManagerController extends BaseController {

    @Autowired
    private LogManagerService logManagerService;


    /**********************************************
     * *****************日志条件公共接**************
     * *****************xutao************************
     */
    @LogAnnotation(module = "日志管理", logType = LogTypeEnum.业务日志, description = "查询条件动态生成", logLevel = LogLevelEnum.低)
    @RequestMapping(value = "/findLogQueryField", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    public BaseResponse findLogQueryField(@RequestParam(value = "pageType", required = false) String code) {
        try {
            if (StringUtils.isEmpty(code)) {
                return this.error(Constant.SYSTEM_EXCEPTION, "表的编码不能为空");
            }
            return this.ok(logManagerService.findLogQueryField(code));
        } catch (Exception e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }


    /************
     ** 探针设备**
     ************/

    /**
     * ========================用户访问日志
     */
    @LogAnnotation(module = "日志管理", logType = LogTypeEnum.业务日志, description = "动态查询日志管理的数据", logLevel = LogLevelEnum.低)
    @RequestMapping(value = "/findDeviceLogByPage", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse findDeviceLogByPage(@RequestBody LogSearchBasicVi record, HttpServletRequest request) {
        try {
            String ipSer = request.getRemoteAddr().replace(".", "");
            record.setClientIp(ipSer);
            Page page = logManagerService.findDeviceLogByPage(record);
            return this.ok(page);
        } catch (KmgaDefinedException ex) {
            return this.error(Constant.SYSTEM_EXCEPTION, ex.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }

    /**
     * 导出日志
     *
     * @param request
     * @param response
     */
    @LogAnnotation(module = "日志管理", logType = LogTypeEnum.业务日志, description = "导出日志", logLevel = LogLevelEnum.低)
    @RequestMapping(value = "/downLoadLog", method = RequestMethod.POST)
    public void downLoadLog(WebRequest request,HttpServletRequest servletRequest, HttpServletResponse response) {
        ServletOutputStream outputStream = null;
        try {
            Data params = getParam(request);
            String json = params.getString("postData");
            LogSearchBasicVi record = JSON.parseObject(json, LogSearchBasicVi.class);
            String fileName = ResLogType.getPageName(record.getPageType()) + "_" + DateUtils.format(new Date(), DateUtils.DATE_FORMAT_6);
            String ipSer = servletRequest.getRemoteAddr().replace(".", "");
            record.setClientIp(ipSer);
            record.setNotExport(false);
            LogPage ret = logManagerService.findExportLogData(record);
            //封装表头
            List<String> headers = ret.getTableHead();
            response.reset();
            //1.通过response获取ServletOutputStream对象(out)
            outputStream = response.getOutputStream();
            //2、设置文件ContentType类型，这样设置，会自动判断下载文件类型
            response.setContentType("application/download; charset=UTF-8");
            //将数据导出成文件,需要判断导出是什么文件,默认导出.xls

            String suffixFileName = fileName + ".xlsx";
            //3.设置文件头：最后一个参数是设置下载文件名
            response.setHeader("Content-Disposition", "attachment;fileName=" + new String(suffixFileName.getBytes("gbk"), "iso-8859-1"));
            List<List<String>> exportData = ret.getContent();
            ExcelExportUtil.exportXlxsExcel(fileName, headers, exportData, outputStream);
        } catch (KmgaDefinedException ex) {
            PrintWriter out = null;
            try {
                response.setCharacterEncoding("UTF-8");
                response.setContentType("application/json; charset=utf-8");
                out = response.getWriter();
                out.append(ex.getMessage());
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (out != null) {
                    out.close();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 获取设备日志详情
     *
     * @param id
     * @return
     */
    @LogAnnotation(module = "日志管理", logType = LogTypeEnum.业务日志, description = "日志详情查询", logLevel = LogLevelEnum.低)
    @RequestMapping(value = "/findDeviceLogById", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    public BaseResponse findDeviceLogById(@RequestParam(value = "id", required = false) String id,
                                          @RequestParam(value = "pageType", required = false) String pageType,
                                          @RequestParam(value = "time", required = false) String time) {
        try {
            if (StringUtils.isEmpty(id)) {
                return this.error(Constant.SYSTEM_EXCEPTION, "日志编号不能为空！");
            }
            return this.ok(logManagerService.findLogDetailById(id, pageType, time));
        } catch (Exception e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }

    /**
     * 数据库静态脱敏
     *
     * @param id ID
     * @return
     */
    @LogAnnotation(module = "日志管理", logType = LogTypeEnum.业务日志, description = "数据库静态脱敏日志详情", logLevel = LogLevelEnum.低)
    @RequestMapping(value = "/findJTDataBaseLogById", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    public BaseResponse findJTDataBaseLogById(@RequestParam(value = "id", required = false) String id) {
        try {
            if (StringUtils.isEmpty(id)) {
                return this.error(Constant.SYSTEM_EXCEPTION, "日志编号不能为空！");
            }
            return this.ok(logManagerService.findLogDetailById(id, ResLogType.JTTMHbase.toString(), null));
        } catch (Exception e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }

    /**
     * 数据库动态脱敏详情
     *
     * @param id ID
     * @return
     */
    @LogAnnotation(module = "日志管理", logType = LogTypeEnum.业务日志, description = "数据库动态脱敏详情", logLevel = LogLevelEnum.低)
    @RequestMapping(value = "/findDTDataBaseDeseLogById", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    public BaseResponse findDTDataBaseDeseLogById(@RequestParam(value = "id", required = false) String id) {
        try {
            if (StringUtils.isEmpty(id)) {
                return this.error(Constant.SYSTEM_EXCEPTION, "日志编号不能为空！");
            }
            return this.ok(logManagerService.findLogDetailById(id, ResLogType.DTTMMySql.toString(), null));
        } catch (Exception e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }

    /**
     * 文件动态脱敏详情
     *
     * @param id ID
     * @return
     */
    @LogAnnotation(module = "日志管理", logType = LogTypeEnum.业务日志, description = "文件动态脱敏详情", logLevel = LogLevelEnum.低)
    @RequestMapping(value = "/findFileDeseLogById", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    public BaseResponse findFileDeseLogById(@RequestParam(value = "id", required = false) String id) {
        try {
            if (StringUtils.isEmpty(id)) {
                return this.error(Constant.SYSTEM_EXCEPTION, "日志编号不能为空！");
            }
            return this.ok(logManagerService.findLogDetailById(id, ResLogType.WJJTTM.toString(), null));
        } catch (Exception e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }

    /**
     * 获取用户行为日志 通过分页
     *
     * @param logSearchUserBehaviorVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getUserBehaviorLogByPage", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse getUserBehaviorLogByPage(@RequestBody LogSearchUserBehaviorVi logSearchUserBehaviorVi) {
        try {
            Data params = new Data();
            Data dataMap = RequestBody2DataMap(logSearchUserBehaviorVi);
            Page page = logManagerService.getUserBehaviorLogByPage(dataMap);
            return this.ok(page);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION, e.getMessage());
        }
    }


    /**
     * 获取用户行为日志
     *
     * @param logSearchUserBehaviorVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/uploadUserBehaviorLog", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse uploadUserBehaviorLog(@RequestBody LogSearchUserBehaviorVi logSearchUserBehaviorVi,
                                              HttpServletResponse response) {
        ServletOutputStream outputStream = null;
        try {
            Data params = new Data();
            Map<String, String> headMap = new HashMap<>();
            headMap.put("name", "xingm");
            headMap.put("id", "haha");
            headMap.put("ss", "lala");
            Data dataMap = RequestBody2DataMap(logSearchUserBehaviorVi);
            List<Map<String, String>> bodyMap = logManagerService.getUserBehaviorLog(dataMap);
            bodyMap.add(headMap);
            String fileName = "123";


            //1.通过response获取ServletOutputStream对象(out)
            outputStream = response.getOutputStream();
            //2、设置文件ContentType类型，这样设置，会自动判断下载文件类型
            response.setContentType("application/download; charset=UTF-8");
            //将数据导出成文件,需要判断导出是什么文件,默认导出.xls

            String suffixFileName = fileName + ".xls";
            //3.设置文件头：最后一个参数是设置下载文件名
            response.setHeader("Content-Disposition", "attachment;fileName=" + new String(suffixFileName.getBytes("gbk"), "iso-8859-1"));
            ExcelExportUtil.createWorkBookForMap(bodyMap, fileName, headMap, outputStream);
            return this.ok(1);

        } catch (NoSuchMethodException e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION);
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    /**
     * ========================特权操作日志
     */

    /**
     * 获取特权操作日志 通过分页
     *
     * @param logSearchUserBehaviorVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getPrivilegedOperationLogByPage", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse getPrivilegedOperationLogByPage(@RequestBody LogSearchUserBehaviorVi logSearchUserBehaviorVi) {
        try {
            Data params = new Data();
            Data dataMap = RequestBody2DataMap(logSearchUserBehaviorVi);
            Page page = logManagerService.getPrivilegedOperationLogByPage(dataMap);
            return this.ok(page);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }


    /**
     * 获取特权操作日志
     *
     * @param logSearchUserBehaviorVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/uploadPrivilegedOperationLog", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse uploadPrivilegedOperationLog(@RequestBody LogSearchUserBehaviorVi logSearchUserBehaviorVi,
                                                     HttpServletResponse response) {
        ServletOutputStream outputStream = null;
        try {
            Data params = new Data();
            Map<String, String> headMap = new HashMap<>();
            headMap.put("name", "xingm");
            headMap.put("id", "haha");
            headMap.put("ss", "lala");
            Data dataMap = RequestBody2DataMap(logSearchUserBehaviorVi);
            List<Map<String, String>> bodyMap = logManagerService.getPrivilegedOperationLog(dataMap);
            bodyMap.add(headMap);
            String fileName = "123";


            //1.通过response获取ServletOutputStream对象(out)
            outputStream = response.getOutputStream();
            //2、设置文件ContentType类型，这样设置，会自动判断下载文件类型
            response.setContentType("application/download; charset=UTF-8");
            //将数据导出成文件,需要判断导出是什么文件,默认导出.xls

            String suffixFileName = fileName + ".xls";
            //3.设置文件头：最后一个参数是设置下载文件名
            response.setHeader("Content-Disposition", "attachment;fileName=" + new String(suffixFileName.getBytes("gbk"), "iso-8859-1"));
            ExcelExportUtil.createWorkBookForMap(bodyMap, fileName, headMap, outputStream);
            return this.ok(1);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            e.printStackTrace();
            return this.error(Constant.SYSTEM_EXCEPTION);
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    /**
     * ========================查询工具日志
     */

    /**
     * 获取查询工具日志 通过分页
     *
     * @param logSearchUserBehaviorVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getQueryToolLogByPage", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse getQueryToolLogByPage(@RequestBody LogSearchUserBehaviorVi logSearchUserBehaviorVi) {
        try {
            Data params = new Data();
            Data dataMap = RequestBody2DataMap(logSearchUserBehaviorVi);
            Page page = logManagerService.getQueryToolLogByPage(dataMap);
            return this.ok(page);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }


    /**
     * 获取查询工具日志
     *
     * @param logSearchUserBehaviorVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/uploadQueryToolLog", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse uploadQueryToolLog(@RequestBody LogSearchUserBehaviorVi logSearchUserBehaviorVi,
                                           HttpServletResponse response) {
        ServletOutputStream outputStream = null;
        try {
            Data params = new Data();
            Map<String, String> headMap = new HashMap<>();
            headMap.put("name", "xingm");
            headMap.put("id", "haha");
            headMap.put("ss", "lala");
            Data dataMap = RequestBody2DataMap(logSearchUserBehaviorVi);
            List<Map<String, String>> bodyMap = logManagerService.getQueryToolLog(dataMap);
            bodyMap.add(headMap);
            String fileName = "123";


            //1.通过response获取ServletOutputStream对象(out)
            outputStream = response.getOutputStream();
            //2、设置文件ContentType类型，这样设置，会自动判断下载文件类型
            response.setContentType("application/download; charset=UTF-8");
            //将数据导出成文件,需要判断导出是什么文件,默认导出.xls

            String suffixFileName = fileName + ".xls";
            //3.设置文件头：最后一个参数是设置下载文件名
            response.setHeader("Content-Disposition", "attachment;fileName=" + new String(suffixFileName.getBytes("gbk"), "iso-8859-1"));
            ExcelExportUtil.createWorkBookForMap(bodyMap, fileName, headMap, outputStream);
            return this.ok(1);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    /**************
     ** 脱敏日志 **
     *************/

    /**
     * ========================数据库静态脱敏
     */

    /**
     * 获取数据库静态脱敏日志 通过分页
     *
     * @param logSearchUserBehaviorVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getDataBaseStaticDesensitizationLogByPage", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse getDataBaseStaticDesensitizationLogByPage(@RequestBody LogSearchUserBehaviorVi logSearchUserBehaviorVi) {
        try {
            Data params = new Data();
            Data dataMap = RequestBody2DataMap(logSearchUserBehaviorVi);
            Page page = logManagerService.getDataBaseStaticDesensitizationLogByPage(dataMap);
            return this.ok(page);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }


    /**
     * 获取数据库静态脱敏日志
     *
     * @param logSearchUserBehaviorVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/uploadDataBaseStaticDesensitizationLog", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse uploadDataBaseStaticDesensitizationLog(@RequestBody LogSearchUserBehaviorVi logSearchUserBehaviorVi,
                                                               HttpServletResponse response) {
        ServletOutputStream outputStream = null;
        try {
            Data params = new Data();
            Map<String, String> headMap = new HashMap<>();
            headMap.put("name", "xingm");
            headMap.put("id", "haha");
            headMap.put("ss", "lala");
            Data dataMap = RequestBody2DataMap(logSearchUserBehaviorVi);
            List<Map<String, String>> bodyMap = logManagerService.getDataBaseStaticDesensitizationLog(dataMap);
            bodyMap.add(headMap);
            String fileName = "123";


            //1.通过response获取ServletOutputStream对象(out)
            outputStream = response.getOutputStream();
            //2、设置文件ContentType类型，这样设置，会自动判断下载文件类型
            response.setContentType("application/download; charset=UTF-8");
            //将数据导出成文件,需要判断导出是什么文件,默认导出.xls

            String suffixFileName = fileName + ".xls";
            //3.设置文件头：最后一个参数是设置下载文件名
            response.setHeader("Content-Disposition", "attachment;fileName=" + new String(suffixFileName.getBytes("gbk"), "iso-8859-1"));
            ExcelExportUtil.createWorkBookForMap(bodyMap, fileName, headMap, outputStream);
            return this.ok(1);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    /**
     * ========================数据库动态脱敏日志
     */

    /**
     * 获取数据库动态脱敏 通过分页
     *
     * @param logSearchUserBehaviorVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getDataBaseDynamicDesensitizationLogByPage", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse getDataBaseDynamicDesensitizationLogByPage(@RequestBody LogSearchUserBehaviorVi logSearchUserBehaviorVi) {
        try {
            Data params = new Data();
            Data dataMap = RequestBody2DataMap(logSearchUserBehaviorVi);
            Page page = logManagerService.getDataBaseDynamicDesensitizationLogByPage(dataMap);
            return this.ok(page);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }


    /**
     * 获取数据库动态脱敏日志
     *
     * @param logSearchUserBehaviorVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/uploadDataBaseDynamicDesensitizationLog", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse uploadDataBaseDynamicDesensitizationLog(@RequestBody LogSearchUserBehaviorVi logSearchUserBehaviorVi,
                                                                HttpServletResponse response) {
        ServletOutputStream outputStream = null;
        try {
            Data params = new Data();
            Map<String, String> headMap = new HashMap<>();
            headMap.put("name", "xingm");
            headMap.put("id", "haha");
            headMap.put("ss", "lala");
            Data dataMap = RequestBody2DataMap(logSearchUserBehaviorVi);
            List<Map<String, String>> bodyMap = logManagerService.getDataBaseDynamicDesensitizationLog(dataMap);
            bodyMap.add(headMap);
            String fileName = "123";


            //1.通过response获取ServletOutputStream对象(out)
            outputStream = response.getOutputStream();
            //2、设置文件ContentType类型，这样设置，会自动判断下载文件类型
            response.setContentType("application/download; charset=UTF-8");
            //将数据导出成文件,需要判断导出是什么文件,默认导出.xls

            String suffixFileName = fileName + ".xls";
            //3.设置文件头：最后一个参数是设置下载文件名
            response.setHeader("Content-Disposition", "attachment;fileName=" + new String(suffixFileName.getBytes("gbk"), "iso-8859-1"));
            ExcelExportUtil.createWorkBookForMap(bodyMap, fileName, headMap, outputStream);
            return this.ok(1);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    /**
     * ========================文件静态脱敏日志
     */

    /**
     * 获取文件静态脱敏日志 通过分页
     *
     * @param logSearchFileDesensitizationVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getFileStaticDesensitizationLogByPage", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse getFileStaticDesensitizationLogByPage(@RequestBody LogSearchFileDesensitizationVi logSearchFileDesensitizationVi) {
        try {
            Data params = new Data();
            Data dataMap = RequestBody2DataMap(logSearchFileDesensitizationVi);
            Page page = logManagerService.getFileStaticDesensitizationLogByPage(dataMap);
            return this.ok(page);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }


    /**
     * 获取文件静态脱敏日志
     *
     * @param logSearchFileDesensitizationVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/uploadFileStaticDesensitizationLog", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse uploadFileStaticDesensitizationLog(@RequestBody LogSearchFileDesensitizationVi logSearchFileDesensitizationVi,
                                                           HttpServletResponse response) {
        ServletOutputStream outputStream = null;
        try {
            Data params = new Data();
            Map<String, String> headMap = new HashMap<>();
            headMap.put("name", "xingm");
            headMap.put("id", "haha");
            headMap.put("ss", "lala");
            Data dataMap = RequestBody2DataMap(logSearchFileDesensitizationVi);
            List<Map<String, String>> bodyMap = logManagerService.getFileStaticDesensitizationLog(dataMap);
            bodyMap.add(headMap);
            String fileName = "123";


            //1.通过response获取ServletOutputStream对象(out)
            outputStream = response.getOutputStream();
            //2、设置文件ContentType类型，这样设置，会自动判断下载文件类型
            response.setContentType("application/download; charset=UTF-8");
            //将数据导出成文件,需要判断导出是什么文件,默认导出.xls

            String suffixFileName = fileName + ".xls";
            //3.设置文件头：最后一个参数是设置下载文件名
            response.setHeader("Content-Disposition", "attachment;fileName=" + new String(suffixFileName.getBytes("gbk"), "iso-8859-1"));
            ExcelExportUtil.createWorkBookForMap(bodyMap, fileName, headMap, outputStream);
            return this.ok(1);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    /**
     * ========================文件动态脱敏日志
     */

    /**
     * 获取文件动态脱敏日志 通过分页
     *
     * @param logSearchFileDesensitizationVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getFileDynamicDesensitizationLogByPage", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse getFileDynamicDesensitizationLogByPage(@RequestBody LogSearchFileDesensitizationVi logSearchFileDesensitizationVi) {
        try {
            Data params = new Data();
            Data dataMap = RequestBody2DataMap(logSearchFileDesensitizationVi);
            Page page = logManagerService.getFileDynamicDesensitizationLogByPage(dataMap);
            return this.ok(page);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }


    /**
     * 获取文件动态脱敏日志
     *
     * @param logSearchFileDesensitizationVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/uploadFileDynamicDesensitizationLog", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse uploadFileDynamicDesensitizationLog(@RequestBody LogSearchFileDesensitizationVi logSearchFileDesensitizationVi,
                                                            HttpServletResponse response) {
        ServletOutputStream outputStream = null;
        try {
            Data params = new Data();
            Map<String, String> headMap = new HashMap<>();
            headMap.put("name", "xingm");
            headMap.put("id", "haha");
            headMap.put("ss", "lala");
            Data dataMap = RequestBody2DataMap(logSearchFileDesensitizationVi);
            List<Map<String, String>> bodyMap = logManagerService.getFileDynamicDesensitizationLog(dataMap);
            bodyMap.add(headMap);
            String fileName = "123";


            //1.通过response获取ServletOutputStream对象(out)
            outputStream = response.getOutputStream();
            //2、设置文件ContentType类型，这样设置，会自动判断下载文件类型
            response.setContentType("application/download; charset=UTF-8");
            //将数据导出成文件,需要判断导出是什么文件,默认导出.xls

            String suffixFileName = fileName + ".xls";
            //3.设置文件头：最后一个参数是设置下载文件名
            response.setHeader("Content-Disposition", "attachment;fileName=" + new String(suffixFileName.getBytes("gbk"), "iso-8859-1"));
            ExcelExportUtil.createWorkBookForMap(bodyMap, fileName, headMap, outputStream);
            return this.ok(1);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    /**************
     ** 运维日志 **
     *************/

    /**
     * ========================运维操作日志
     */

    /**
     * 获取运维操作日志 通过分页
     *
     * @param logSearchMaintenanceOperationVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getMaintenanceOperationLogByPage", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse getMaintenanceOperationLogByPage(@RequestBody LogSearchMaintenanceOperationVi logSearchMaintenanceOperationVi) {
        try {
            Data params = new Data();
            Data dataMap = RequestBody2DataMap(logSearchMaintenanceOperationVi);
            Page page = logManagerService.getMaintenanceOperationLogByPage(dataMap);
            return this.ok(page);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }


    /**
     * 获取运维操作日志
     *
     * @param logSearchMaintenanceOperationVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/uploadMaintenanceOperationLog", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse uploadMaintenanceOperationLog(@RequestBody LogSearchMaintenanceOperationVi logSearchMaintenanceOperationVi,
                                                      HttpServletResponse response) {
        ServletOutputStream outputStream = null;
        try {
            Data params = new Data();
            Map<String, String> headMap = new HashMap<>();
            headMap.put("name", "xingm");
            headMap.put("id", "haha");
            headMap.put("ss", "lala");
            Data dataMap = RequestBody2DataMap(logSearchMaintenanceOperationVi);
            List<Map<String, String>> bodyMap = logManagerService.getMaintenanceOperationLog(dataMap);
            bodyMap.add(headMap);
            String fileName = "123";


            //1.通过response获取ServletOutputStream对象(out)
            outputStream = response.getOutputStream();
            //2、设置文件ContentType类型，这样设置，会自动判断下载文件类型
            response.setContentType("application/download; charset=UTF-8");
            //将数据导出成文件,需要判断导出是什么文件,默认导出.xls

            String suffixFileName = fileName + ".xls";
            //3.设置文件头：最后一个参数是设置下载文件名
            response.setHeader("Content-Disposition", "attachment;fileName=" + new String(suffixFileName.getBytes("gbk"), "iso-8859-1"));
            ExcelExportUtil.createWorkBookForMap(bodyMap, fileName, headMap, outputStream);
            return this.ok(1);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    /**************
     ** 系统日志 **
     *************/

    /**
     * ========================监管平台日志
     */

    /**
     * 获取监管平台日志 通过分页
     *
     * @param logSearchRegulatoryPlatformVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getRegulatoryPlatformLogByPage", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse getRegulatoryPlatformLogByPage(@RequestBody LogSearchRegulatoryPlatformVi logSearchRegulatoryPlatformVi) {
        try {
            Data params = new Data();
            Data dataMap = RequestBody2DataMap(logSearchRegulatoryPlatformVi);
            Page page = logManagerService.getRegulatoryPlatformLogByPage(dataMap);
            return this.ok(page);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }


    /**
     * 获取监管平台日志
     *
     * @param logSearchRegulatoryPlatformVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/uploadRegulatoryPlatformLog", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse uploadRegulatoryPlatformLog(@RequestBody LogSearchRegulatoryPlatformVi logSearchRegulatoryPlatformVi,
                                                    HttpServletResponse response) {
        ServletOutputStream outputStream = null;
        try {
            Data params = new Data();
            Map<String, String> headMap = new HashMap<>();
            headMap.put("name", "xingm");
            headMap.put("id", "haha");
            headMap.put("ss", "lala");
            Data dataMap = RequestBody2DataMap(logSearchRegulatoryPlatformVi);
            List<Map<String, String>> bodyMap = logManagerService.getRegulatoryPlatformLog(dataMap);
            bodyMap.add(headMap);
            String fileName = "123";


            //1.通过response获取ServletOutputStream对象(out)
            outputStream = response.getOutputStream();
            //2、设置文件ContentType类型，这样设置，会自动判断下载文件类型
            response.setContentType("application/download; charset=UTF-8");
            //将数据导出成文件,需要判断导出是什么文件,默认导出.xls

            String suffixFileName = fileName + ".xls";
            //3.设置文件头：最后一个参数是设置下载文件名
            response.setHeader("Content-Disposition", "attachment;fileName=" + new String(suffixFileName.getBytes("gbk"), "iso-8859-1"));
            ExcelExportUtil.createWorkBookForMap(bodyMap, fileName, headMap, outputStream);
            return this.ok(1);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    /**
     * ========================探针设备日志
     */

    /**
     * 获取探针设备日志 通过分页
     *
     * @param logSearchRegulatoryPlatformVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getProbeEquipmentLogByPage", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse getProbeEquipmentLogByPage(@RequestBody LogSearchRegulatoryPlatformVi logSearchRegulatoryPlatformVi) {
        try {
            Data params = new Data();
            Data dataMap = RequestBody2DataMap(logSearchRegulatoryPlatformVi);
            Page page = logManagerService.getProbeEquipmentLogByPage(dataMap);
            return this.ok(page);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }


    /**
     * 获取探针设备日志
     *
     * @param logSearchRegulatoryPlatformVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/uploadProbeEquipmentLog", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse uploadProbeEquipmentLog(@RequestBody LogSearchRegulatoryPlatformVi logSearchRegulatoryPlatformVi,
                                                HttpServletResponse response) {
        ServletOutputStream outputStream = null;
        try {
            Data params = new Data();
            Map<String, String> headMap = new HashMap<>();
            headMap.put("name", "xingm");
            headMap.put("id", "haha");
            headMap.put("ss", "lala");
            Data dataMap = RequestBody2DataMap(logSearchRegulatoryPlatformVi);
            List<Map<String, String>> bodyMap = logManagerService.getProbeEquipmentLog(dataMap);
            bodyMap.add(headMap);
            String fileName = "123";


            //1.通过response获取ServletOutputStream对象(out)
            outputStream = response.getOutputStream();
            //2、设置文件ContentType类型，这样设置，会自动判断下载文件类型
            response.setContentType("application/download; charset=UTF-8");
            //将数据导出成文件,需要判断导出是什么文件,默认导出.xls

            String suffixFileName = fileName + ".xls";
            //3.设置文件头：最后一个参数是设置下载文件名
            response.setHeader("Content-Disposition", "attachment;fileName=" + new String(suffixFileName.getBytes("gbk"), "iso-8859-1"));
            ExcelExportUtil.createWorkBookForMap(bodyMap, fileName, headMap, outputStream);
            return this.ok(1);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    /**
     * ========================脱敏设备日志
     */

    /**
     * 获取脱敏设备日志 通过分页
     *
     * @param logSearchRegulatoryPlatformVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getDesensitizationEquipmentLogByPage", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse getDesensitizationEquipmentLogByPage(@RequestBody LogSearchRegulatoryPlatformVi logSearchRegulatoryPlatformVi) {
        try {
            Data params = new Data();
            Data dataMap = RequestBody2DataMap(logSearchRegulatoryPlatformVi);
            Page page = logManagerService.getDesensitizationEquipmentLogByPage(dataMap);
            return this.ok(page);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }


    /**
     * 获取脱敏设备日志
     *
     * @param logSearchRegulatoryPlatformVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/uploadDesensitizationEquipmentLog", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse uploadDesensitizationEquipmentLog(@RequestBody LogSearchRegulatoryPlatformVi logSearchRegulatoryPlatformVi,
                                                          HttpServletResponse response) {
        ServletOutputStream outputStream = null;
        try {
            Data params = new Data();
            Map<String, String> headMap = new HashMap<>();
            headMap.put("name", "xingm");
            headMap.put("id", "haha");
            headMap.put("ss", "lala");
            Data dataMap = RequestBody2DataMap(logSearchRegulatoryPlatformVi);
            List<Map<String, String>> bodyMap = logManagerService.getDesensitizationEquipmentLog(dataMap);
            bodyMap.add(headMap);
            String fileName = "123";


            //1.通过response获取ServletOutputStream对象(out)
            outputStream = response.getOutputStream();
            //2、设置文件ContentType类型，这样设置，会自动判断下载文件类型
            response.setContentType("application/download; charset=UTF-8");
            //将数据导出成文件,需要判断导出是什么文件,默认导出.xls

            String suffixFileName = fileName + ".xls";
            //3.设置文件头：最后一个参数是设置下载文件名
            response.setHeader("Content-Disposition", "attachment;fileName=" + new String(suffixFileName.getBytes("gbk"), "iso-8859-1"));
            ExcelExportUtil.createWorkBookForMap(bodyMap, fileName, headMap, outputStream);
            return this.ok(1);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    /**
     * ========================运维设备日志
     */

    /**
     * 获取运维设备日志 通过分页
     *
     * @param logSearchRegulatoryPlatformVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getMaintenanceEquipmentLogByPage", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse getMaintenanceEquipmentLogByPage(@RequestBody LogSearchRegulatoryPlatformVi logSearchRegulatoryPlatformVi) {
        try {
            Data params = new Data();
            Data dataMap = RequestBody2DataMap(logSearchRegulatoryPlatformVi);
            Page page = logManagerService.getMaintenanceEquipmentLogByPage(dataMap);
            return this.ok(page);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }


    /**
     * 获取运维设备日志 通过分页
     *
     * @param logSearchRegulatoryPlatformVi 搜索条件
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/uploadMaintenanceEquipmentLog", method = RequestMethod.POST, produces = {"application/json", "application/xml"})
    public BaseResponse uploadMaintenanceEquipmentLog(@RequestBody LogSearchRegulatoryPlatformVi logSearchRegulatoryPlatformVi,
                                                      HttpServletResponse response) {
        ServletOutputStream outputStream = null;
        try {
            Data params = new Data();
            Map<String, String> headMap = new HashMap<>();
            headMap.put("name", "xingm");
            headMap.put("id", "haha");
            headMap.put("ss", "lala");
            Data dataMap = RequestBody2DataMap(logSearchRegulatoryPlatformVi);
            List<Map<String, String>> bodyMap = logManagerService.getMaintenanceEquipmentLog(dataMap);
            bodyMap.add(headMap);
            String fileName = "123";


            //1.通过response获取ServletOutputStream对象(out)
            outputStream = response.getOutputStream();
            //2、设置文件ContentType类型，这样设置，会自动判断下载文件类型
            response.setContentType("application/download; charset=UTF-8");
            //将数据导出成文件,需要判断导出是什么文件,默认导出.xls

            String suffixFileName = fileName + ".xls";
            //3.设置文件头：最后一个参数是设置下载文件名
            response.setHeader("Content-Disposition", "attachment;fileName=" + new String(suffixFileName.getBytes("gbk"), "iso-8859-1"));
            ExcelExportUtil.createWorkBookForMap(bodyMap, fileName, headMap, outputStream);
            return this.ok(1);
        } catch (NoSuchMethodException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (InvocationTargetException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IntrospectionException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (IllegalAccessException e) {
            return this.error(Constant.SYSTEM_EXCEPTION, "参数错误");
        } catch (Exception e) {
            return this.error(Constant.SYSTEM_EXCEPTION);
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    /**
     * 请求体转化为Data类型
     *
     * @param object
     * @return
     * @throws IntrospectionException
     * @throws NoSuchMethodException
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    public Data RequestBody2DataMap(Object object) throws IntrospectionException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Data dataMap = new Data();
        Class type = object.getClass();
        //将参数中的四个参数分别取出
        Method methodPage = type.getDeclaredMethod("getPage");
        Method methodPageSize = type.getDeclaredMethod("getPageSize");
        Method methodTop1 = type.getDeclaredMethod("getTop1");
        Method methodTop2 = type.getDeclaredMethod("getTop2");
        Integer page = (Integer) methodPage.invoke(object);
        Integer pageSize = (Integer) methodPageSize.invoke(object);
        Object top1 = (Object) methodTop1.invoke(object);
        Object top2 = (Object) methodTop2.invoke(object);

        if (page == null || page < 0) {
            dataMap.put("page", 1);
        } else {
            dataMap.put("page", page);
        }

        if (pageSize == null || pageSize < 0) {
            dataMap.put("pageSize", 5);
        } else {
            dataMap.put("pageSize", pageSize);
        }
        //将top1转化成 map
        Map<String, Object> mapTop1 = new HashMap();
        mapTop1 = BeanToMapUtil.convertBean(top1);
        if (mapTop1.containsKey("dateRange") && mapTop1.get("dateRange") != null && !"".equals(mapTop1.get("dateRange").toString())) {
            String[] times = mapTop1.get("dateRange").toString().split("-");
            dataMap.put("starTime", times[0].trim() + times[1].trim() + times[2].trim());
            dataMap.put("endTime", times[3].trim() + times[4].trim() + times[5].trim());
            mapTop1.remove("dateRange");
        } else {
            //否则将今天传入参数
            String dateTimes = new SimpleDateFormat("yyyymmdd").format(new Date());
            dataMap.put("starTime", dateTimes);
            dataMap.put("endTime", dateTimes);
        }

        Map<String, Object> mapTemp = Maps.newHashMap();
        //遍历map将没有值的去掉 或者值为-1的
        for (Map.Entry<String, Object> entry : mapTop1.entrySet()) {
            if (entry.getValue() != null && !"-1".equals(entry.getValue().toString()) && !"".equals(entry.getValue().toString())) {
                if ("keyType".equals(entry.getKey()) && mapTop1.get("keyValue") != null && "".equals(mapTop1.get("keyValue").toString().trim())) {
                    continue;
                } else {
                    mapTemp.put(entry.getKey(), entry.getValue());
                }
            }
        }
        dataMap.put("top1", mapTemp);
        //将top1中的时间取出来
        //放入data中
        Map<String, Object> mapTop2 = new HashMap();
        mapTop2 = BeanToMapUtil.convertBean(top2);
        //将top2转化成 map
        Map<String, Object> mapTemp2 = Maps.newHashMap();
        //遍历map将没有值的去掉 或者值为-1的
        for (Map.Entry<String, Object> entry : mapTop2.entrySet()) {
            if (entry.getValue() != null && !"-1".equals(entry.getValue().toString()) && !"".equals(entry.getValue().toString())) {
                mapTemp2.put(entry.getKey(), entry.getValue());
            }
        }
        dataMap.put("top2", mapTemp2);
        return dataMap;
    }
}
